import * as actionType from './actionType'

// 系统权限初始数据
const initState = {
    departmentList: [{
        key: 1,
        department_name: '风控部',
        function_des: '暂无描述',
        member_num: 10,
        add_time: '2022-1-7 18:00',
        is_enable: 0
    }, {
        key: 2,
        department_name: '风控部',
        function_des: '暂无描述',
        member_num: 10,
        add_time: '2022-1-7 18:00',
        is_enable: 1
    }],

    roleList: [{
        key: 1,
        role_name: '风控部经理',
        role_des: '暂无描述',
        role_add_time: '2022-1-8 12:00'
    }, {
        key: 2,
        role_name: '贷前文员',
        role_des: '暂无描述',
        role_add_time: '2022-1-8 12:00'
    }],

    staffList: [{
        key: 1,
        member_account: 'User1',
        member_name: '北极熊',
        member_phone: '18888888888',
        member_email: '1158900247@qq.com',
        department_name: '运营部',
        role_name: '风控经理',
        last_login: '2022-1-8 18:00',
        is_enable: 0
    }, {
        key: 2,
        member_account: 'User2',
        member_name: '北极熊',
        member_phone: '18888888888',
        member_email: '1158900247@qq.com',
        department_name: '运营部',
        role_name: '风控经理',
        last_login: '2022-1-8 18:00',
        is_enable: 1
    }, {
        key: 3,
        member_account: 'User3',
        member_name: '北极熊',
        member_phone: '18888888888',
        member_email: '1158900247@qq.com',
        department_name: '运营部',
        role_name: '风控经理',
        last_login: '2022-1-8 18:00',
        is_enable: 1
    }, {
        key: 4,
        member_account: 'User3',
        member_name: '北极熊',
        member_phone: '18888888888',
        member_email: '1158900247@qq.com',
        department_name: '运营部',
        role_name: '风控经理',
        last_login: '2022-1-8 18:00',
        is_enable: 1
    }],

    serviceList: [{
        key: 1,
        member_account: 'user',
        service_name: '小熊',
        service_phone: '18888888888',
        service_qq: '888888888',
        service_add_time: '2022-1-10 00:00',
        service_last_login: '2022-1-10 12:00',
        is_enable: 0
    },
    {
        key: 2,
        member_account: 'user',
        service_name: '小熊',
        service_phone: '18888888888',
        service_qq: '888888888',
        service_add_time: '2022-1-10 00:00',
        service_last_login: '2022-1-10 12:00',
        is_enable: 1
    }],

    databaseList: [{
        key: 1,
        file_name: '2018101652225.bak',
        version_num: '4.0',
        byte_size: '15902208',
        file_time: '2018-08-05 15:47'
    },
    {
        key: 2,
        file_name: '2018101652225.bak',
        version_num: '4.0',
        byte_size: '15902208',
        file_time: '2018-08-05 15:47'
    }, {
        key: 3,
        file_name: '2018101652225.bak',
        version_num: '4.0',
        byte_size: '15902208',
        file_time: '2018-08-05 15:47'
    }]
}

function reducer(state = initState, action) {
    switch (action.type) {
        case actionType.DEPARTMENT_LIST:
            return [
                ...state,
                ...action
            ]
        case actionType.DEPARTMENT_UPDATE:
            var departmentList = state.departmentList.map(item => {
                if (item.key === action.values.key) {
                    item.is_enable = action.values.is_enable
                }
                return item
            })

            console.log("state.departmentList:", state.departmentList);
            return {
                ...state,
                departmentList
            }

        case actionType.DEPARTMENT_DEL:
            console.log("action.key:", action.key);
            var departmentList = state.departmentList.filter(item => item.key != action.key)
            console.log(departmentList);
            return {
                ...state,
                departmentList
            }

        default:
            return state
    }
}

export default reducer